<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>团购商品修改</h2>
    </div>
    <div class="tab-wrap">
        <ul class="tab-nav nav">
            <li data-tab="tab1" class="current"><a href="#">基础</a></li>
            <li data-tab="tab2" ><a href="#">扩展</a></li>
        </ul>
        <div class="tab-content">
            <form id="form" action="{:U('')}" method="post" class="form-horizontal">
                <input type="hidden" name='id' value='{$data.Product.id}'/>
                <div id="tab1" class="tab-pane tab1 in">
                    <!--TAB S-->
                    <div class="form-item cf">
                        <label class="item-label">商品名称<span class="check-tips">（输入商品的名称）</span></label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="proName" value="{$data.Product.proName}">
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">所属活动<span class="check-tips">（选择商品的所属活动）</span></label>
                        <div class="controls">
                            <select name="gpId" class="select input-large">
                                <volist name="data.list" id="vo">
                                    <option value="{$vo.id}">{$vo.gpName}</option>
                                </volist>
                            </select>
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">商品简介<span class="check-tips">（输入商品简介）</span></label>
                        <div class="controls">
                            <label class="textarea input-large">
                                <textarea name="intro">{$data.Product.intro}</textarea>
                            </label>
                        </div>
                    </div>

                    <div class="form-item cf">
                        <label class="item-label">商品详情<span class="check-tips">（输入商品详情）</span></label>
                        <div class="controls">

                            {:hook('adminArticleEdit', array('name'=>'content'))}

                            <textarea name="content">{$data.Product.content}</textarea>
                        </div>
                    </div>


                    <!--tab e-->
                </div>
                <div id="tab2" class="tab-pane tab2">
                    <div class="form-item cf">
                        <label class="item-label">商品橱窗图片<span class="check-tips">(商品主图尺寸建议)</span></label>
                        <div class="controls">

                            <php>
                                $picarry = $data['Product']['picarry'];
                            </php>
                            {:hook('UploadImages', array('name'=>"picarry",'value'=>"$picarry"))}

                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">团购分级<span class="check-tips"><a href='#' class='btn btn-primary' id="addspec">添加新分级</a></span></label>
                        <div class="controls">
                            <div style="border: #000 1px solid;width:100%" class='data-table table-striped'>

                                <table >
                                    <thead>
                                        <tr>
                                            <th>条件</th>                                         
                                            <th>优惠</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="tbodyspec">
                                        <volist name="data.spclist" id="vo">
                                            <tr id="spec_{$vo.id}">
                                                <td>销量满：<input type="text" class="text input-small" name="saleCnt" value="{$vo.saleCnt}" placeholder="" >份</td>
                                                <td>团购价为：<input type="number" class="text input-small" name="price" value="{$vo.price}" placeholder="" >元</td>
                                                <td><a href='#' class='btn btn-primary specmodifyajax' data-pid="{$vo.proId}" data-id="{$vo.id}" >修改</a> <a href='#' class='btn btn-primary specdelajax' data-pid="{$vo.proId}" data-id="{$vo.id}">删除</a></td>
                                            </tr>
                                        </volist>
                                    </tbody>
                                </table>


                            </div>
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">最大购买量</label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="maxCnt" value="{$data.Product.maxCnt}">
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">最小购买量</label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="minCnt" value="{$data.Product.minCnt}">
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">已售量</label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="gpsaleCnt" value="{$data.Product.saleCnt}">
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">果然价</label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="grprice" value="{$data.Product.grprice}">
                        </div>
                    </div>
                    <div class="form-item cf">
                        <label class="item-label">开团价</label>
                        <div class="controls">
                            <input type="text" class="text input-large" name="gpprice" value="{$data.Product.price}">
                        </div>
                    </div>
                    
                </div>
                <div class="form-item cf">
                    <button class="btn submit-btn  ajax-post" id="submit" type="submit" target-form="form-horizontal" autocomplete="off">保存商品</button>
                    <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
                </div>
            </form>
        </div>
    </div>
</block>

<block name="script">
    <script type="text/javascript">
        $(document).ready(function () {
            $(".tab-nav > li").click(function () {
                var tab = $(this).data('tab');
                $(".tab-nav > li").removeClass('current');
                $(this).addClass('current');
                $(".tab-pane").removeClass('in');
                var obj = $('#' + tab);
                obj.addClass('in');
            });
            ///
            $('#addspec').click(function () {
                var html='<tr><td>销量满：<input type="text" class="text input-small" name="newsaleCnt[]" value="" placeholder="" >份</td><td>团购价为：<input type="number" class="text input-small" name="newprice[]" value="" placeholder="" >元</td><td> <a href="#" class="btn btn-primary trdelspec">删除</a></td></tr>';
                $('#tbodyspec').append(html);
                
                
                $('.trdelspec').bind("click", function(){
                $(this).parent().parent().remove();
                 });
             });
            
            
            ///
            $('.specmodifyajax').click(function () {
                var id = $(this).data('id');
                var pid = $(this).data('pid');
                var specarr = Array();
                $(this).parents("tr").find('td input').each(function () {
                    specarr[$(this).attr('name')] = $(this).val();
                });
                
                $(this).parents("tr").find('td input[type=checkbox]').each(function () {
                    var checkbloean =$(this).prop('checked');
                    if(checkbloean){
                           specarr[$(this).attr('name')] =1 ;
                    }else{
                           specarr[$(this).attr('name')] = 0;
                    }
                 
                   
                });
                   
                $.post("{:U('GroupPurchase/speceditajax')}", {id: id,price:specarr['price'],saleCnt:specarr['saleCnt']},
                function (data) {
                    alert(data.info); 
                }, "json");

            });
            
             $('.specdelajax').click(function () {
                 if(window.confirm("请仔细核确认，需要删除此规格吗？")){
                      var id = $(this).data('id');
                        var pid = $(this).data('pid');
                        var THIS= $(this).parent().parent();
                        $.post("{:U('GroupPurchase/specdelajax')}", {id: id},
                        function (data) {
                            alert(data.info); 
                            THIS.remove();
                        }, "json");
                 }
            });
        });
        highlight_subnav('{:U('GroupPurchase/proindex')}');
    </script>
</block>